package 笔试.MiHoYo;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class 连通大陆 {
    public static int[][] dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
    public static char[][] matrix;
    public static int n;
    public static int m;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        in.nextLine();
        matrix = new char[n][m];
        int begi = -1;
        int begj = -1;
        Queue<int[]> queue = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            matrix[i] = in.nextLine().toCharArray();
            for (int j = 0; j < m; j++) {
                if (matrix[i][j] == '#' && begi == -1) {
                    begi = i;
                    begj = j;
                } else if (matrix[i][j] == '.') {
                    queue.add(new int[]{i, j});
                }
            }
        }
        boolean[][] visited = new boolean[n][m];
        ArrayList<int[]> res = new ArrayList<>();
        ArrayList<int[]> list = new ArrayList<>();
        int maxSea = 0;
        while (!queue.isEmpty()) {
            int[] poll = queue.poll();
            int x = poll[0];
            int y = poll[1];
            if (visited[x][y]) {
                continue;
            }
            Queue<int[]> bfsQueue = new LinkedList<>();
            bfsQueue.add(new int[]{x, y});
            list.add(new int[]{x, y});
            int temp = 1;
            visited[x][y] = true;
            while (!bfsQueue.isEmpty()) {
                int[] bfspoll = bfsQueue.poll();
                int bfsx = bfspoll[0];
                int bfsy = bfspoll[1];
                for (int i = 0; i < 4; i++) {
                    int tx = bfsx + dir[i][0];
                    int ty = bfsy + dir[i][1];
                    if (tx < 0 || tx >= n || ty < 0 || ty >= m) {
                        continue;
                    }
                    if (visited[tx][ty] || matrix[tx][ty] == '#') {
                        continue;
                    }
                    temp++;
                    visited[tx][ty] = true;
                    bfsQueue.add(new int[]{tx, ty});
                    list.add(new int[]{tx, ty});
                }
            }
            if (maxSea < temp) {
                res = new ArrayList<>(list);
            }
            maxSea = Math.max(maxSea, temp);
            list.clear();
        }
        for (int[] ints : res) {
//            System.out.println(ints[0] + " " + ints[1]);
            matrix[ints[0]][ints[1]] = '#';
        }

        Queue<int[]> last = new LinkedList<>();
        last.add(new int[]{begi, begj});
        int temp = 1;
        visited = new boolean[n][m];
        visited[begi][begj] = true;
        while (!last.isEmpty()) {
            int[] bfspoll = last.poll();
            int bfsx = bfspoll[0];
            int bfsy = bfspoll[1];
            for (int i = 0; i < 4; i++) {
                int tx = bfsx + dir[i][0];
                int ty = bfsy + dir[i][1];
                if (tx < 0 || tx >= n || ty < 0 || ty >= m) {
                    continue;
                }
                if (visited[tx][ty] || matrix[tx][ty] != '#') {
                    continue;
                }
                temp++;
                visited[tx][ty] = true;
                last.add(new int[]{tx, ty});
            }
        }
        System.out.println(temp);
    }

}